<template>
    <view class="mine-container"> <!--顶部个人信息栏-->
        <view class="header-section">
            <image v-if="!userInfo.avatarUrl" src="../../static/images/mine/mine_personal.svg"></image>
            <image v-if="userInfo.avatarUrl" style="width: 124rpx;height: 124rpx;" :src="baseUrl + userInfo.avatarUrl"></image>
            <view @click="handleTo" class="user-info">
                <view class="u_name"> {{ userInfo.userName || '点击登录' }}</view>
                <view class="u_type" v-if="userInfo.userTypeName"> <image src="../../static/images/mine/mine_unit.svg"></image> {{ userInfo.userTypeName }}</view>
            </view>
        </view>
        <view class="mine-lists">
            <view class="mine-list" @click="handleToCollect">
                <image src="../../static/images/mine/mine_collect.svg"></image>
                <view>我的收藏</view>
                <image src="../../static/images/mine/mine_right.svg"></image>
            </view>
            <view class="mine-list" @click="handleToContribution">
                <image src="../../static/images/mine/mine_contribute.svg"></image>
                <view>贡献值管理</view>
                <image src="../../static/images/mine/mine_right.svg"></image>
            </view>
            <view class="mine-list" @click="handleToInterest">
                <image src="../../static/images/mine/mine_interest.svg"></image>
                <view>兴趣标签选择</view>
                <image src="../../static/images/mine/mine_right.svg"></image>
            </view>
            <view class="mine-list" @click="handleToPwd" v-if="userInfo.type == 1">
                <image src="../../static/images/mine/mine_password.svg"></image>
                <view>修改密码</view>
                <image src="../../static/images/mine/mine_right.svg"></image>
            </view>
			<view class="mine-list" @click="handleToFeedback">
			    <image src="../../static/images/mine/mine_feedback.svg"></image>
			    <view>问题反馈</view>
				<view class="badge-box" v-if="isAdmin">
					<u-badge numberType="overflow" max="99" type="error" :value="unProcessedCount" bgColor="#EA0000"></u-badge>
				</view>
				<image src="../../static/images/mine/mine_right.svg" v-else></image>
			</view>
			<view class="mine-list" @click="handleToWeb">
			    <image src="../../static/images/mine/mine_web_site.svg"></image>
			    <view>电脑登录网址</view>
			    <image src="../../static/images/mine/mine_right.svg"></image>
			</view>
        </view>
        <u-button type="primary" class="btn" @click="handleLogout">退出登录</u-button>
    </view>
</template>

<script>
export default {
    data() {
        return {
            name: this.$store.state.user.name,
            // version: getApp().globalData.config.appInfo.version,
            userInfo:{},
			unProcessedCount: 0,
			isAdmin: false,
            baseUrl: '',
        }
    },
    computed: {
        avatar() {
            return this.$store.state.user.avatar
        },
        windowHeight() {
            return uni.getSystemInfoSync().windowHeight - 50
        }
    },
    onShow(){
        this.userInfoFn();
		this.getUnprocessed()
        this.getUserRole()
        this.baseUrl = uni.$config.baseUrl
    },
    methods: {
        userInfoFn(){
            this.$request({
                url:'/user/currentUser',
                method:'get'
            }).then(({ data })=>{
                console.log("看看这个个人信息",data)
                this.userInfo = data
            })
        },
		getUnprocessed() {
			this.$request({
			    url:'/feedback/unprocessed/count',
			    method:'get'
			}).then(({ data })=>{
				this.unProcessedCount = data
			})
		},
		getUserRole() {
			this.$request({
				url: "/user/adminRole",
				method: "get",
				params: {
					userId: uni.getStorageSync("user").id
				},
			}).then(({data}) => {
				console.log(data)
				this.isAdmin = data
			})
		},
        handleTo() {
            if (this.name) {
                this.$tab.navigateTo('/pages/mine/info/index')
            } else {
                this.$tab.reLaunch('/pages/login')
            }
        },
        handleToEditInfo() {
            this.$tab.navigateTo('/pages/mine/info/edit')
        },
        handleToSetting() {
            this.$tab.navigateTo('/pages/mine/setting/index')
        },
        handleToAvatar() {
            this.$tab.navigateTo('/pages/mine/avatar/index')
        },
        handleLogout() {
            this.$modal.confirm('确定注销并退出系统吗？').then(() => {
                this.$store.dispatch('LogOut').then(() => {
                    this.$tab.reLaunch('/pages/index')
                })
            })
        },
        handleHelp() {
            this.$tab.navigateTo('/pages/mine/help/index')
        },
        handleAbout() {
            this.$tab.navigateTo('/pages/mine/about/index')
        },
        handleJiaoLiuQun() {
            this.$modal.showToast('QQ群：①133713780、②146013835')
        },
        handleBuilding() {
            this.$modal.showToast('模块建设中~')
        },
        handleToCollect() {
            this.$tab.navigateTo('/pages/mine/collect/index')
        },
        handleToContribution() {
            this.$tab.navigateTo('/pages/mine/contribution/index')
        },
        handleToInterest() {
            this.$tab.navigateTo('/pages/mine/interest/index')
        },
        handleToPwd() {
            this.$tab.navigateTo('/pages/mine/pwd/index')
        },
		handleToFeedback() {
			this.$tab.navigateTo('/pages/mine/feedback/index')
		},
		handleToWeb() {
			this.$tab.navigateTo('/pages/mine/website/index')
		}
    }
} </script>
<style lang="scss" scoped>
.mine-container {
    .header-section {
        height: 264rpx;
        color: #FFFFFF;
        background: #54aafc;
        border-radius: 0px 0px 32rpx 32rpx;
        font-family: Source Han Sans;
        font-size: 36rpx;
        display: grid;
        grid-template-columns: 120rpx 1fr;
        grid-column-gap: 28rpx;
        align-items: center;
        padding: 0 72rpx;
        image{
            width: 120rpx;
            height: 120rpx;
            border-radius: 50%;
            border: 4rpx solid #8fc8fe;
        }
        .login-tip {
            font-size: 36rpx;
        }
        
        .user-info {
            .u_name {
                padding: 0 14rpx 22rpx ;
            }
            
            .u_type {
                height: 60rpx;
                border-radius: 40rpx;
                background: rgba(255, 255, 255, 0.8);
                border: 2rpx solid #FFFFFF;
                color: #0084FF;
                padding: 0 20rpx;
                font-size: 28rpx;
                display: flex;
                align-items: center;
                width: max-content;
                image{
                    width: 36rpx;
                    height: 28rpx;
                    margin-right: 12rpx;
                    border-radius: 100%;
                    border: none;
                }
            }
        }
    }
    
    .mine-lists{
        padding: 40rpx 30rpx;
        .mine-list{
            height: 100rpx;
            border-radius: 16rpx;
            display: grid;
            grid-template-columns: 32rpx 1fr 48rpx;
            padding: 0 20rpx;
            grid-column-gap: 26rpx;
            background: #FFFFFF;
            align-items: center;
            font-family: 思源黑体;
            font-size: 30rpx;
            image{
                width: 32rpx;
                height: 32rpx;
            }
            & +.mine-list{
                margin-top: 20rpx;
            }
            & :last-child image{
                width: 48rpx;
                height: 48rpx;
            }
			.badge-box{
				display: flex;
				align-items: center;
				::v-deep .u-badge {
					width: 36rpx;
					height: 36rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 24rpx;
					line-height: 24rpx;
					padding: 0;
				}
			}
        }
		.mine-list:nth-last-child(1) {
			grid-template-columns: 32rpx 1fr 54rpx;
		}
    }
    
    .btn{
        width: calc(100% - 60rpx);
        margin: 0 30rpx;
        height: 100rpx;
        border-radius: 16rpx;
        background: #0084FF;
        font-family: Poppins;
        font-size: 32rpx;
        font-weight: 600;
    }
}
</style>